how to differentiate a complex function